package com.neutech.dao.impl;

import com.neutech.dao.FoodDAO;
import com.neutech.entity.Food;
import org.apache.commons.dbutils.ResultSetHandler;

import static com.neutech.constant.Constant.queryRuner;;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;


public class FoodDAOImpl implements FoodDAO {

    @Override
    public List<Food> showFoodAll() {
        List<Food> foodList = new ArrayList<>();
        try {
            queryRuner.execute("select * from food", new ResultSetHandler<Object>() {
                @Override
                public Object handle(ResultSet resultSet) throws SQLException {
                    while (resultSet.next()) {
                        Food food = new Food();
                        food.setFoodName(resultSet.getString("food_name"));
                        food.setFoodExplain(resultSet.getString("food_explain"));
                        food.setFoodPrice(resultSet.getBigDecimal("food_price"));
                        food.setBusinessId(resultSet.getInt("business_id"));
                        foodList.add(food);
                    }
                    return foodList;
                }
            });
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return foodList;
    }

    @Override
    public void insert(Food food) {

    }

    @Override
    public void update(Food food) {

    }

    @Override
    public Food selectFoodName(String foodName) {
        return null;
    }

    @Override
    public void delete(Food food) {

    }


}
